using System;
using System.Collections.Generic;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace GCalSync
{
    class Util
    {
        public static void WriteDebugMessage(string message)
        {
            System.Diagnostics.Debug.WriteLine(message);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ai"></param>
        /// <param name="fieldName"></param>
        /// <param name="fieldValue"></param>
        public static void AddCustomField(Outlook.AppointmentItem ai, string fieldName, string fieldValue)
        {
            Outlook.UserProperty up = ai.UserProperties.Find(fieldName, System.Reflection.Missing.Value);
            if (up == null)
            {
                up = ai.UserProperties.Add(fieldName, Outlook.OlUserPropertyType.olText, true,
                    System.Reflection.Missing.Value);
                // and then add the label
                up.Value = fieldValue;
            }
            else
            {
                up.Value = fieldValue;
            }
            ai.Save();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ai"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static string GetCustomField(Outlook.AppointmentItem ai, string fieldName)
        {
            Outlook.UserProperty up = ai.UserProperties.Find(fieldName, System.Reflection.Missing.Value);
            if (up == null)
                return null;
            else
                return up.Value.ToString();
        }
    }
}
